package com.example.demo.dao;

import com.example.demo.model.ArticleInfo;
import com.example.demo.model.vo.UserInfoVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: wenjingyuan
 * @Date: 2023/08/01/10:59
 * @Description:
 */
public interface ArticleMapper {
    //文章倒序显示
    @Select("select * from articleinfo where uid=#{uid} order by id desc")
    List<ArticleInfo> getListByUid(@Param("uid") int uid);

    @Delete("delete from articleinfo where id=#{aid} and uid=#{uid}")
    int del(@Param("aid")Integer aid,int uid);

    @Insert("insert into articleinfo(title,content,uid) values(#{title},#{content},#{uid})")
    int add(ArticleInfo articleInfo);

    @Select("select * from articleinfo where id=#{aid} and uid=#{uid}")
    ArticleInfo getArticleByIdAndUid(@Param("aid")int aid,@Param("uid")int uid);

    @Update("update  articleinfo set title=#{title},content=#{content} where id=#{id} and uid=#{uid}")
    int update(ArticleInfo articleInfo);

    @Select("select * from articleinfo where id=#{aid}")
    ArticleInfo detail(@Param("aid")int aid);


    @Select("select COUNT(*) from articleinfo where uid=#{uid}")
    int gerArtCount(@Param("uid")int uid);

    @Update("update articleinfo set rcount=rcount+1 where id=#{aid}")
    int incrementRcount(@Param("aid" )int aid);

    @Select("select * from articleinfo order by id desc limit #{psize} offset #{offset} ")
    List<ArticleInfo> getListBySize(@Param("psize")int psize,@Param("offset")int offset);

    @Select("select COUNT(*) from articleinfo")
    int gerCount();
}
